// 导入vue-router
import { createRouter, createWebHistory } from 'vue-router'

// 导入组件
import Layout from '@/view/Layout.vue'
import HomePage from '@/view/homePage/HomePage.vue';
import ArticleDetail from '@/view/articleDetail/ArticleDetail.vue';
import ArticleEditPost from '@/view/articleEditPost/ArticleEditPost.vue';
import UserCenter from '@/view/userCenter/UserCenter.vue';
import UserArticle from '@/view/userCenter/UserArticle.vue';
import UserComment from '@/view/userCenter/UserComment.vue';
import UserLikeRecord from '@/view/userCenter/UserLikeRecord.vue';
import SearchArticle from '@/view/homePage/SearchArticle.vue';
import UpdateLayout from '@/view/userCenter/settings/UpdateLayout.vue';
import UpdateUserInfo from '@/view/userCenter/settings/UpdateUserInfo.vue';
import Test01 from '@/view/zzzTest/Test01.vue';

// 定义路由与组件的关系
const routes = [
  {
    path: '/',
    component: Layout,
    children: [ // 子路由
      { path: '/', name: '主页', component: HomePage },
      { path: '/:boardName1', name: '一级板块主页', component: HomePage },
      { path: '/:boardName1/:boardName2', name: '二级板块主页', component: HomePage },
      { path: '/article/detail/:articleId', name: '文章详情页', component: ArticleDetail },
      { path: '/search', name: '文章搜索页', component: SearchArticle },
      {
        path: '/userCenter/:userId',
        name: '用户中心',
        component: UserCenter,
        children: [
          { path: '/userCenter/:userId/article', name: '文章管理页', component: UserArticle },
          { path: '/userCenter/:userId/comment', name: '评论管理页', component: UserComment },
          { path: '/userCenter/:userId/like', name: '点赞管理页', component: UserLikeRecord },
        ]
      },
      {
        path: '/user/settings',
        name: '用户信息页',
        component: UpdateLayout,
        children: [
          { path: '/user/settings/profile', name: '更新用户信息页', component: UpdateUserInfo },
        ]
      },
    ]
  },
  { path: '/article/post', name: '发布文章', component: ArticleEditPost },
  { path: '/article/edit/:articleId', name: '编辑文章', component: ArticleEditPost },

  { path: '/test', name: '测试用页面', component: Test01 },
]

// 创建路由器
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL), // 路由模式
  routes: routes
});

// 导出路由
export default router